package com.ruoyi.web.controller.tea;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tea.domain.TeaFactory;
import com.ruoyi.tea.service.ITeaFactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author hmx
 * @date 2023-03-10
 */
@RestController
@RequestMapping("/tea/factory")
public class TeaFactoryController extends BaseController
{
    @Autowired
    private ITeaFactoryService teaFactoryService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('tea:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaFactory teaFactory)
    {
        startPage();
        List<TeaFactory> list = teaFactoryService.selectTeaFactoryList(teaFactory);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('tea:factory:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaFactory teaFactory)
    {
        List<TeaFactory> list = teaFactoryService.selectTeaFactoryList(teaFactory);
        ExcelUtil<TeaFactory> util = new ExcelUtil<TeaFactory>(TeaFactory.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('tea:factory:query')")
    @GetMapping(value = "/{factoryId}")
    public AjaxResult getInfo(@PathVariable("factoryId") Long factoryId)
    {
        return success(teaFactoryService.selectTeaFactoryByFactoryId(factoryId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('tea:factory:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaFactory teaFactory)
    {
        return toAjax(teaFactoryService.insertTeaFactory(teaFactory));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('tea:factory:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaFactory teaFactory)
    {
        return toAjax(teaFactoryService.updateTeaFactory(teaFactory));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('tea:factory:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factoryIds}")
    public AjaxResult remove(@PathVariable Long[] factoryIds)
    {
        return toAjax(teaFactoryService.deleteTeaFactoryByFactoryIds(factoryIds));
    }
}
